package com.luke.zk;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @Descrtption CuratorCreate
 * @Author luke
 * @Date 2020/5/22
 **/
public class CuratorDelete {

    private String IP = "192.168.0.17:2181";

    private CuratorFramework client;

    @Before
    public void before(){
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3);
        client = CuratorFrameworkFactory.builder()
                .connectString(IP)//地址端口
                .sessionTimeoutMs(5000)//会话超时
                .retryPolicy(retryPolicy)//重连机制
                .namespace("create")//命名空间
                .build();
        client.start();
    }

    @After
    public void after(){
        client.close();
    }

    @Test
    public void delete1() throws Exception{
       client.delete().forPath("/node3");
    }

    @Test
    public void delete2() throws Exception{
        client.delete().withVersion(3).forPath("/node2");
    }

}
